#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 3e5 + 10;

int n, Q, stu[N], tot;
ll ans[N];
char t[N];

struct line {
	int op, t, l, r; 
} p[N << 2];

set < pii > s;

void addline(int t, int l, int r) { if(l <= r) s.ep(l, r), p[++tot] = (line) { 1, t, l, r }; }
void delline(int t, int l, int r) { if(l <= r) s.erase(pii(l, r)), p[++tot] = (line) { -1, t, l, r }; }

ll tr1[N], tr2[N];
void add(ll *tr, int x, int v) { for(; x; x -= x & -x) tr[x] += v; }
int query(ll * tr, int x) { ll res = 0; for(; x <= n; x += x & -x) res += tr[x]; return res; }
void clr(ll *tr, int x) { for(; x; x -= x & -x) tr[x] = 0; }

void solve(int l, int r) {
	if(l == r) return; int mid = l + r >> 1;
	solve(l, mid); solve(mid + 1, r);
	int p1 = l, p2 = mid + 1;
	
	while(p1 <= mid && p2 <= r) {
		if(p[p1].l <= p[p2].l) {
			if(p[p1].op != 0) add(tr1, p[p1].r, p[p1].op), add(tr2, p[p1].r, -p[p1].t * p[p1].op);
			p1++;
		} else {
			if(p[p2].op == 0) ans[p[p2].t] += query(tr2, p[p2].r) + query(tr1, p[p2].r) * p[p2].t;
			p2++;
		}
	}
	while(p2 <= r) {
		if(p[p2].op == 0) ans[p[p2].t] += query(tr2, p[p2].r) + query(tr1, p[p2].r) * p[p2].t;
		p2++;
	}
	for(p1--; p1 >= l; p1--) if(p[p1].op != 0) clr(tr1, p[p1].r), clr(tr2, p[p1].r);
	/*
	rep(i, l, mid)
		if(p[i].op != 0)
			rep(j, mid + 1, r)
				if(p[j].op == 0 && p[i].l <= p[j].l && p[i].r >= p[j].r && p[i].t <= p[j].t) {
					ans[p[j].t] += p[i].op * (p[j].t - p[i].t);
				}
	*/
	inplace_merge(p + l, p + mid + 1, p + r + 1,
				  [](auto a, auto b) {
					  return a.l ^ b.l ? a.l < b.l : a.r ^ b.r ? a.r > b.r : a.t ^ b.t ? a.t < b.t : abs(a.op) > abs(b.op);
				  });
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in, Q = in; scanf("%s", t + 1);
	int lst = 1;
	rep(i, 1, n) {
		stu[i] = t[i] - '0';
		if(stu[i] == 0) addline(0, lst, i - 1), lst = i + 1;
	} addline(0, lst, n);
	rep(i, 1, Q) {
		scanf("%s", t + 1); int x = in, y;
		if(t[1] == 't') {
			if(stu[x] == 0) {
				int l = x, r = x;
				if(stu[x - 1] == 1) {
					auto it = s.upper_bound({ x, x }); it--;
					l = it -> fi; delline(i, it -> fi, it -> se);
				}
				if(stu[x + 1] == 1) {
					auto it = s.lower_bound({ x + 1, x + 1 });
					r = it -> se; delline(i, it -> fi, it -> se);
				}
				addline(i, l, r);
			} else {
				auto it = s.upper_bound({ x + 1, x }); it--;
				int l = it -> fi, r = it -> se; delline(i, l, r);
				addline(i, l, x - 1); addline(i, x + 1, r);
			} stu[x] ^= 1;
			ans[i] = -1;
		} else {
			y = in; p[++tot] = (line) { 0, i, x, y - 1 };
		}
	}
	sort(p + 1, p + tot + 1,
		 [](auto a, auto b) {
			 return a.t ^ b.t ? a.t < b.t : a.l ^ b.l ? a.l < b.l : a.r ^ b.r ? a.r > b.r : (abs(a.op) > abs(b.op));
		 });
	//	rep(i, 1, tot) cerr << p[i].op << " " <<p[i].t << " " << p[i].l << " " << p[i].r << endl;
	solve(1, tot); rep(i, 1, Q) if(ans[i] != -1) printf("%lld\n", ans[i]);
	return 0;
}
